import { PORT1 } from "@/api/config/servicePort";
import http from "@/api";
import { ReqPage, ResPage } from "../interface";
export const loadPage = (params: CodegenTable.ReqCodegenTable) => {
  return http.get<ResPage<CodegenTable.ResCodegenTable>>(PORT1 + `/system/sys-codegen-table/page`, params);
};

export const loadTableList = (params: CodegenTable.ReqCodegenTable) => {
  return http.get<CodegenTable.ResDataBaseTable>(PORT1 + `/system/sys-codegen-table/db/list`, params);
};

export const createCodegenTable = (data: CodegenTable.ResCodegenTableSaveVo) => {
  return http.post<Boolean>(PORT1 + `/system/sys-codegen-table/create-list`, data);
};
// 预览生成代码
export const previewCodegen = (id: number | undefined) => {
  return http.get<CodegenTable.CodegenPreviewVO[]>(PORT1 + `/system/sys-codegen-table/preview/${id}`);
};

export const deleteCodegen = (id: number) => {
  return http.delete<Boolean>(PORT1 + `/system/sys-codegen-table/delete/${id}`);
};

export const syncCodegen = (id: number) => {
  return http.put<Boolean>(PORT1 + `/system/sys-codegen-table/sync-from-db/${id}`);
};

export const downLoadCodegen = (id: number) => {
  return http.download(PORT1 + `/system/sys-codegen-table/download/${id}`);
};

export namespace CodegenTable {
  export type CodegenPreviewVO = {
    filePath: string;
    code: string;
  };
  export interface ResCodegenTableSaveVo {
    dataResourceId: number;
    tableNames: string[];
  }
  export interface ResDataBaseTable {
    name: string;
    comment: string;
  }
  export interface ResCodegenTable {
    id: number;
    dataSourceId: number;
    scene: number;
    tableName: string;
    tableComment: string;
    remark: string;
    moduleName: string;
    businessName: string;
    className: string;
    author: string;
    templateType: number;
    frontType: number;
    parentMenuId: number;
    masterTableId: number;
    subJoinColumnId: number;
    subJoinMany: number;
    treeParentColumnId: number;
    treeNameColumnId: number;
    sort: number;
    createBy: number;
    createTime: Date;
    updateBy: number;
    updateTime: Date;
    isDeleted: number;
  }
  export interface ReqCodegenTable extends ReqPage {
    id: number;
    dataSourceId: number;
    scene: number;
    tableName: string;
    tableComment: string;
    remark: string;
    moduleName: string;
    businessName: string;
    className: string;
    author: string;
    templateType: number;
    frontType: number;
    parentMenuId: number;
    masterTableId: number;
    subJoinColumnId: number;
    subJoinMany: number;
    treeParentColumnId: number;
    treeNameColumnId: number;
    sort: number;
    createBy: number;
    createTime: Date;
    updateBy: number;
    updateTime: Date;
    isDeleted: number;
  }
}
